#!/usr/bin/python

from splitdump import SplitDump
from sqltoxml import SqlToXml
from optparse import OptionParser

class Context():
    options = None
    args = None

    def __init__(self, options, args):
        self.options = options
        self.args = args

def handle_exit(message):
    print message
    parser.print_help()
    exit(-1)

if __name__ == "__main__":
    parser = OptionParser()
    parser.add_option('-s', '--source-file', help='File containing input data')
    parser.add_option('-o', '--output-file', help='File to write the output to')
    parser.add_option('-x', '--schema-file', help='File containing schema. i.e. columns')

    (options, args) = parser.parse_args()
    context = Context(options, args)

    tasks = []
    if len(args) == 0:
        handle_exit('No arguments given')
    else:
        for task in args:
            if task == 'splitdump':
                tasks.append(SplitDump(context))
            elif task == 'sqltoxml':
                tasks.append(SqlToXml(context))
            else:
                handle_exit('unknown argument: ' + task)
            tasks[len(tasks)-1].execute()
